{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Python中的sklearn库里有一个RidgeCV类，它可以基于交叉验证实现Ridge回归，现基于iris数据集，对该类的使用方法进行说明"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "系数: [-0.20370879  0.21952122  0.52216614]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import RidgeCV\n",
    "import pandas as pd\n",
    "iris=pd.read_csv(\"http://image.cador.cn/data/iris.csv\")\n",
    "x = iris.iloc[:,[0,1,2]].values\n",
    "y = iris.iloc[:,3].values\n",
    "\n",
    "# 通过RidgeCV可以设置多个参数值，算法使用交叉验证获取最佳参数值\n",
    "model = RidgeCV(alphas=[0.1, 10, 10000])  \n",
    "\n",
    "# 线性回归建模\n",
    "model.fit(x, y)   \n",
    "\n",
    "print('系数:',model.coef_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.2437781946128439"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.intercept_ "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
